package com.itheima;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Emp;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
public class QueryMapper {
    @Autowired
    private EmpMapper empMapper;
    @Test
    public void testQuery(){
       QueryWrapper<Emp> qw=new QueryWrapper();
        qw.like("name","李").ge("salary",5000).select("id","name","phone","salary");
        List<Emp> emps = empMapper.selectList(qw);
        System.out.println(emps);

    }

    @Test
    public void testLambadaQueryWrapper(){
        LambdaQueryWrapper<Emp> lqw=new LambdaQueryWrapper<>();
        lqw.like(Emp::getName,"李").ge(Emp::getSalary,5000).select(Emp::getId,Emp::getName,Emp::getPhone,Emp::getSalary);
        List<Emp> emps = empMapper.selectList(lqw);
        System.out.println(emps);
    }

    @Test
    public void testUpdateWrapper(){
        UpdateWrapper<Emp> uw=new UpdateWrapper<>();
        uw.in("id",1,2).setSql("salary=salary+2000");
        empMapper.update(uw);
    }

    @Test
    public void testLambadaUpdateWrapper(){
        LambdaUpdateWrapper<Emp> luw=new LambdaUpdateWrapper();
        luw.in(Emp::getId,1,2).setSql("salary=salary+2000");
        empMapper.update(luw);
    }
}
